package com.centling.smartSealForPhone.activity

import android.content.Context
import android.os.Bundle
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.centling.smartSealForPhone.R
import com.centling.smartSealForPhone.bean.DetailBean
import kotlinx.android.synthetic.main.activity_history_stamp_records.*
import kotlinx.android.synthetic.main.rv_approval_time_item.view.*

/**
 * Created by fionera on 16-10-10.
 */
class HistoryApprovalRecordsActivity : TitleBarActivity() {

    private lateinit var historyStampList: List<DetailBean.SealApplyAuditRecordListEntity>

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_history_stamp_records)

        setTitleBarText("审阅记录")
        setTitleBarVisibility(View.VISIBLE)

        historyStampList = intent.getParcelableArrayListExtra("history_stamp_records")

        rv_history_stamp_records.layoutManager = GridLayoutManager(mContext, 1)
        rv_history_stamp_records.adapter = HistoryApprovalRecordsAdapter(mContext, historyStampList)
    }

    inner class HistoryApprovalRecordsAdapter(var context: Context, var data: List<DetailBean.SealApplyAuditRecordListEntity>) : RecyclerView.Adapter<HistoryStampRecordsHolder>() {
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HistoryStampRecordsHolder = HistoryStampRecordsHolder(LayoutInflater.from(mContext).inflate(R.layout.rv_approval_time_item, parent, false))

        override fun onBindViewHolder(holder: HistoryStampRecordsHolder, position: Int) {
            holder.itemView.tv_history_stamp_approval_name.text = data[position].applyTasterStr
            holder.itemView.tv_history_stamp_approval_previous_name.text = data[position].applyAssignorStr
            holder.itemView.tv_history_stamp_approval_time.text = if (TextUtils.isEmpty(data[position].applyAuditTimeStr)) "未审阅" else data[position].applyAuditTimeStr
            holder.itemView.tv_history_stamp_approval_remarks.text = if (TextUtils.isEmpty(data[position].applyAuditRemark)) "未填写" else data[position].applyAuditRemark
        }

        override fun getItemCount(): Int = data.size
    }

    inner class HistoryStampRecordsHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
}